<template>
  <div class="app-container">
    <div class="custom_card_0" v-show="showSearch">
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="司机名称" prop="driverName">
          <el-input
            v-model="queryParams.driverName"
            placeholder="请输入司机名称"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="下单时间" prop="startTime">
          <el-date-picker clearable size="small" v-model="time" type="daterange" range-separator="至" value-format="yyyy-MM-dd" start-placeholder="开始时间" end-placeholder="结束时间"></el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
          >搜索
          </el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置
          </el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <div class="custom_card">

      <el-table
        v-loading="loading"
        :data="driverPerformanceList"
        @selection-change="handleSelectionChange"
        border
      >
        <el-table-column
          label="司机名称"
          align="center"
          prop="driverName"
          min-width="120"
          show-overflow-tooltip
        />
        <el-table-column
          label="司机类型"
          align="center"
          prop="driverType"
          min-width="120"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.driverType == 1? "内部":'外部' }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="订单数量"
          align="center"
          prop="orderNum"
          min-width="120"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span slot="btn" class="showOderNumber" @click="driverOrderView(scope.row.driverId)">{{scope.row.orderNum}}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="代驾费总计"
          align="center"
          prop="feeTotal"
          min-width="120"
          show-overflow-tooltip
        />
        <el-table-column
          label="代驾总时长(小时)"
          align="center"
          prop="vehicleDurationTotal"
          min-width="120"
          show-overflow-tooltip
        />
        <el-table-column
          label="代驾总公里数(KM)"
          align="center"
          prop="vehicleKilometersTotal"
          min-width="120"
          show-overflow-tooltip
        />

      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />


    </div>

      <MmvOrderList ref="MmvOrderList" ></MmvOrderList>

  </div>

</template>

<script>
import {
  driverPerformanceList
} from '@/api/charteredBus/performance'
import MmvOrderList from './orderList.vue'

export default {
  name: 'DriverPerformance',
  components: {
    MmvOrderList
  },
  dicts: [
    'store_class',
  ],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 司机绩效数据列表
      driverPerformanceList: [],
      time: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tenantId: null,
      },
      // 表单参数
      form: {
        // bindingCharges: 1,
      },
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询收费项列表 */
    getList() {
      this.loading = true
      driverPerformanceList(this.queryParams).then((response) => {
        this.driverPerformanceList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 绑定费用项显示弹框
    driverOrderView(driverId) {
      this.$refs.MmvOrderList.show(driverId);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      if (this.time) {
        this.queryParams.startTime = this.time[0]
        this.queryParams.endTime = this.time[1]
      } else {
        this.queryParams.startTime = null
        this.queryParams.endTime = null
      }
      this.showDriverOrderDetail = false;
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.time = [];
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.driverId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },

    /** 导出按钮操作 */
    // handleExport() {
    //   const queryParams = this.queryParams
    //   this.$modal
    //     .confirm('是否确认导出所有收费项数据项？')
    //     .then(() => {
    //       this.exportLoading = true
    //       return exportItems(queryParams)
    //     })
    //     .then((response) => {
    //       this.$download.name(response.msg)
    //       this.exportLoading = false
    //     })
    //     .catch(() => {
    //     })
    // },
  },
}
</script>
<style>

.showOderNumber {
  position: relative;
  font-size: 14px;
  top: 6px;
  color: #5473E8;
}
</style>
